<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            报工数据
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">产线</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请 扫描/输入 产线" id="workCenterCode" value=""
                            onclick="getIdSelector();">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label" style="width:150px">计划开始日期</div>
                    <div class="aui-list-item-input" onclick="timePicker();">
                        <input type="text" placeholder="选择日期" style="padding-left: 35px;" class="aui-input"
                            id="dateTime">
                    </div>
                </div>
            </li>
        </ul>
        <div style="width:100%;margin-top:2%;"></div>
        <div class="aui-btn aui-btn-info" style="width:45%;margin-left:4%;" onclick="searchDetails()">查询</div>
        <div class="aui-btn aui-btn-info" style="width:45%;margin-left:2%;" onclick="returnProductionReport()">带回</div>
        <div
            style="background-color:white; width: 100%;margin-top:2%;white-space: nowrap;overflow-x: auto;-webkit-overflow-scrolling:touch;">

            <table class="table" style='width:1500px;' id="table1">
                <tbody style="display:block">
                    <tr
                        style="text-align: center;background-color: #DCE9F2;color: #467aa7;font-size: 15px;font-weight: bold;">
                        <td algin='center' style="width:40px;"></td>
                        <td algin='center' style="width:50px;">序号</td>
                        <td algin='center' style="width:130px;"> 工单号</td>
                        <td algin='center' style="width:130px;">产品物料编码</td>
                        <td algin='center' style="width:150px;;">产品物料名称</td>
                        <td algin='center' style="width:100px;">计划开始时间</td>
                        <td algin='center' style="width:100px;">计划结束时间</td>
                        <td algin='center' style="width:150px;">生产线编码</td>
                        <td algin='center' style="width:150px;">生产线名称</td>
                        <td algin='center' style="width:100px;">班次编码</td>
                        <td algin='center' style="width:130px;">班次名称</td>
                        <td algin='center' style="width:80px;">计划数量</td>
                        <td algin='center' style="width:80px;">完工数</td>
                        <td algin='center' style="width:80px;">不合格品数</td>
                    </tr>
                </tbody>
            </table>
            <table class="table" style='width:1500px;' id="table">
                <tbody id="tbodyHtml" style="display: block;height: 700px;overflow-y: scroll;">
                </tbody>
            </table>
        </div>
    </div>
    <div>
        <div style="height:60px;"></div>
        <footer class="aui-bar aui-bar-tab" id="footer">
            <div class="aui-bar-tab-item" tapmode id="scan" onclick="doScan()">
                <i class="aui-iconfont aui-icon-scan aui-text-epblue" style="font-size: 1.8rem"></i>
            </div>
        </footer>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";
    var scanRule = ""; //条码解析规则
    var address = ""

    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

    //初始化查询
    apiready = function () {
        //产线
        $("#workCenterCode").focus();
        idSelector = "workCenterCode";

        searchDetails();

    }

    //扫描
    function doScan() {
        var moduleScanner = api.require('moduleScanner');
        var params = {
            top: 150, //扫描窗口的上边距
            width: 250, //扫描窗口的宽
            height: 250, //扫描窗口的高
            useColor: false, //是否使用自己设定的颜色(startColor和endColor),
            //如果不使用设定的颜色就使用默认的那张网格图
            startColor: '#0F08C8FF', //渐变起始颜色
            endColor: '#7F08C8FF', //渐变结束颜色
            animTime: 2200, //扫描动画时间,单位为毫秒
        };
        moduleScanner.toScannerActivityForResult(params, function (ret, err) {

            //1：产线
            if (idSelector == 'workCenterCode') {

                //校验仓库编码是否存在
                getWorkCenter(ret);
                //2:箱号
            } else if (idSelector == 'opCode') {
                $("#opCode").val(ret);

            }
        });
    }

    //生产线监听回车事件
    $("#workCenterCode").on('keypress', function (e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var workCenterCode = $(this).val();
        if (keycode == '13') {
            //生产线
            $("#workCenterCode").val(workCenterCode);
            getWorkCenter(workCenterCode)
            searchDetails()

        }
    });

    //1：仓库扫描校验
    function getWorkCenter(code) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getWorkCentercode";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                workCenterCode: code,
                mrlCode: "",
                lotCode: "",
                qty: "",
                un : un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {
                    //产线
                    $("#workCenterCode").val(code);
                    searchDetails()

                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                    $("#workCenterCode").val("");
                    idSelector = "workCenterCode";
                    $("#workCenterCode").focus();
                }
            }
        });
    }



    //时间选择器
    function timePicker() {
        api.openPicker({
            type: 'date',
            date: new Date(),
            title: '选择日期'
        }, function (ret, err) {
            if (ret) {
                var monthTemp = (ret.month < 10 ? '0' + ret.month : ret.month);
                var dayTemp = (ret.day < 10 ? '0' + ret.day : ret.day);
                var date = ret.year + "-" + monthTemp + "-" + dayTemp;
                $("#dateTime").val(date);
                searchDetails();
            }
        });
    }

    //查询表格数据
    function searchDetails() {
        var workCenterCode = $("#workCenterCode").val();
        var dateTime = $("#dateTime").val();
        if (workCenterCode == "") {
            return;
        }
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getWorkOrderTable";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                proddate: dateTime,
                linecode: workCenterCode,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //返回成功
                if (myobj.code == "0") {

                    var list = eval(myobj.list);

                    var html = "";

                    //发货单明细数据存在
                    if (list.length > 0) {

                        //遍历
                        for (var i = 0; i < list.length; i++) {
                            html += "<tr style='text-align: center;color: black;font-size: 12px;background-color: #F5F5F5;'>";
                            // html += "<td style='width:40px;'><input name='sub' type='checkbox'  /></td>";
                            html += "<td style='width:40px;'><input name='sub' type='radio'/></td>";
                            html += "<td name='seqNo' style='width:50px;'>" + (i + 1) + "</td>";

                            html += "<td name='code' style='width:130px;'>" + list[i].code + "</td>";

                            html += "<td name='produCode' style='width:130px;'>" + list[i].produCode + "</td>";
                            html += "<td name='produName' style='width:150px;'>" + list[i].produName + "</td>";
                            html += "<td name='plannedBeginDate' style='width:100px;'>" + list[i].plannedBeginDate + "</td>";
                            html += "<td name='plannedEndDate' style='width:100px;'>" + list[i].plannedEndDate + "</td>";
                            html += "<td name='linecode' style='width:150px;'>" + (list[i].linecode == null ? "" : list[i].linecode) + "</td>";
                            html += "<td name='linename'  style='width:150px;'>" + (list[i].linename == null ? "" : list[i].linename) + "</td>";
                            html += "<td name='shiftCode'  style='width:100px;'>" + (list[i].shiftCode == null ? "" : list[i].shiftCode) + "</td>";
                            html += "<td name='shiftName'  style='width:130px;'>" + (list[i].shiftName == null ? "" : list[i].shiftName) + "</td>";
                            html += "<td name='qty'  style='width:80px;'>" + list[i].qty + "</td>";
                            html += "<td name='completeQty'  style='width:80px;'>" + (list[i].completeQty == null ? "" : list[i].completeQty) + "</td>";
                            html += "<td name='ext06'  style='width:80px;'>" + (list[i].ext06 == null ? "" : list[i].ext06) + "</td>";
                            html += "</tr>";
                        }

                    } else {

                    }

                    $api.html($api.byId("tbodyHtml"), html);

                    //失败，存在没有订单数据
                } else if (myobj.code == "1") {

                    $("#consignment").select();
                    idSelector = "consignment";
                    //清空表格数据
                    // $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }
    //选择时带回信息
    function selectChange() {
        var check = $("input[type='radio']:checked");
        console.log(check);

        check.each(function () { //遍历
            var row = $(this).parent("td").parent("tr");
            $("#mrlCode").val(row.find("[name='mrlCode']").html());
            $("#lotCode").val(row.find("[name='lotCode']").html());
            $("#nowQty").val(row.find("[name='qty']").html());
            workCenterCode1 = row.find("[name='workCenterCode']").html();
            workCellCode1 = row.find("[name='workCellCode']").html();
        });
    }

    //选则返回函数
    function returnProductionReport() {
        var workCenterCode = $("#workCenterCode").val();
        var proddate = $("#dateTime").val();
        var workOrderCode = '';
        var produCode = '';
        var check = $("input[type='radio']:checked");
        console.log(JSON.stringify(check.length));

        check.each(function () { //遍历
            var row = $(this).parent("td").parent("tr");
            workOrderCode = row.find("[name='code']").html();
            produCode = row.find("[name='produCode']").html();
            produName = row.find("[name='produName']").html();
            shiftCode = row.find("[name='shiftCode']").html();
            completeQty = row.find("[name='completeQty']").html();
        });
        api.closeWin();
        if (check.length != 0) {
            api.execScript({
                name: 'productionReport',
                script: 'setTable("' + workCenterCode + '","' + workOrderCode + '","' + produCode + '","' + produName + '","' + shiftCode + '","' + completeQty + '","' + proddate + '")'
            });
        } else {
            api.execScript({
                name: 'productionReport',
                script: 'setTable("' + "" + '","' + "" + '","' + "" + '","' + "" + '","' + "" + '","' + "" + '","' + "" + '")'
            });
        }


    }
    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>